(function(w) {
    var APP = {
        getQueryString: function(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return r[2];
            return null;
        },
        setCookie: function(c_name, value, expiredays) {
            var exdate = new Date()
            exdate.setDate(exdate.getDate() + expiredays)
            document.cookie = c_name + "=" + escape(value) +
                ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
        },
        getCookie: function(c_name) {
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(c_name + "=")
                if (c_start != -1) {
                    c_start = c_start + c_name.length + 1
                    c_end = document.cookie.indexOf(";", c_start)
                    if (c_end == -1) c_end = document.cookie.length
                    return unescape(document.cookie.substring(c_start, c_end)) 
                } 
            }
            return ""
        },
        init: function(t,fn,fn2){
            var _csi = this.getCookie('shopid');
            var _tsi = this.getQueryString('storeid');
            if(_csi && _tsi && _csi == _tsi && fn){
                fn && fn.call(t);
            }else{
                Vue.http.post(APIPHP + "index.php?storeid=" + _tsi, {}).then(function(_res) {
                if (_res.body.error_code == 200) {
                    if (_res.body.data.shop.shop_id) {
                        this.setCookie("shopid", _res.body.data.shop.shop_id);
                        this.setCookie("shoplogo", _res.body.data.shop.shop_logo);
                        this.setCookie("shopname", _res.body.data.shop.shop_name);
                        this.setCookie('memberid',_res.body.data.member.member_id);
                        fn2 && fn2.call(null,_res);
                    }

                    } else {
                        return false;
                    }
                }.bind(this), function(_res) {
                });
            }
             
        },
        iswechat: function(){
            var ua = navigator.userAgent.toLowerCase();
            if(ua.match(/MicroMessenger/i)=="micromessenger") {
                return true;
            } else {
                return false;
            }
        },
        isAndroid: function(){
            var ua = navigator.userAgent.toLowerCase();
            var iVal=false;
            if(ua.match(/android/i)){
                iVal=true;
            }
                return iVal;
        },
        version:201707211818
    };
    w.APP = APP;
        Array.prototype.indexOf = function(val) {
        for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
        }
        return -1;
        };
        Array.prototype.remove = function(val) {
        var index = this.indexOf(val);
        if (index > -1) {
        this.splice(index, 1);
        }
        };
        var tmpstoreid=APP.getQueryString('storeid');
        var _url="";
        var _href=window.location.href;
        var isDetail=_href.indexOf('goods-detail.html')>=0?true:false;
        if (isDetail) {
            _url=APIPHP+'index.php?r=home/index/count&storeid='+tmpstoreid+'&vtype=1'
        }else{
            _url=APIPHP+'index.php?r=home/index/count&storeid='+tmpstoreid
        }
        Vue.http.options.xhr = {
            withCredentials: true
        }
        Vue.http.options.credentials = true;
        Vue.http.get(_url).then(function (_res) {

        })
})(window);
